//导入对应组件
import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView'
import LoginView from '../views/LoginView'
import page404 from '../views/404/page404'
import HomeIndex from '../views/Home/HomeIndex'
import HomeDaily from '../views/Home/HomeDaily'
import HomePerson from '../views/Home/HomePerson'
import store from '../store/index'
import ClassInfo from '../views/Home/Index/ClassInfo'
Vue.use(VueRouter)

const routes = [
  {
    path: '*',
    name: 'page404',
    component: page404
  },
  {
    //访问的路径
    path: '/',
    name: 'login',
    // 访问的组件
    component: LoginView
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView,
    meta: { title: '首页面' },
    children: [
      {
        path: 'index',
        name: 'index',
        meta: { title: '首页' },
        component: HomeIndex
      }, {
        path: 'Daily',
        name: 'Daily',
        meta: { title: '发现' },
        component: HomeDaily
      }, {
        path: 'person',
        name: 'person',
        meta: { title: '个人中心' },
        component: HomePerson
      },{
        path: '/classinfo',
        name: 'classinfo',
        component: ClassInfo
      },
      {
        path: '/studentinfo',
        name: 'studentinfo',
        component: () => import('../views/Home/Index/StudentInfo.vue')
      },
      {
        path: '/resourcesview',
        name: 'resourcesview',
        component: () => import('../views/Home/Index/ResourcesView.vue')
      },
      {
        path: '/taskinfo',
        name: 'taskinfo',
        component: () => import('../views/Home/Index/TaskInfo.vue')
      },
      {
        path: '/discuss',
        name: 'discuss',
        component: () => import('../views/Home/Index/DiscussManageView.vue')
      },
      {
        path: '/video',
        name: 'video',
        component: () => import('../views/Home/Index/VideoView.vue')
      },
      {
        path: '/stutaskinfo',
        name: 'stutaskinfo',
        component: () => import('../views/Home/students/TaskInfo.vue')
      },
      {
        path: '/resourcesvinfo',
        name: 'resourcesvinfo',
        component: () => import('../views/Home/students/ResourcesInfo.vue')
      },
      {
        path: '/studentDiscuss',
        name: 'studentDiscuss',
        component: () => import('../views/Home/students/StudentDiscuss.vue')
      },
      {
        path: '/studentVideo',
        name: 'studentVideo',
        component: () => import('../views/Home/students/VideoView.vue')
      },
      {
        path: '/about',
        name: 'about',
        component: () => import('../views/Home/About.vue')
      },
    ]
  },
  
    
]

const router = new VueRouter({
  routes
})
// 路由守卫
router.beforeEach((to, from, next) => {
  // console.log(to);
  // console.log(from);
  if (to.name != "login") {
    if (store.state.token == "") {
      // 未登录
      next('/');
    } else {
      next(true);
    }
  } else {
    next(true);
  }
})



export default router
